<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>一张图设置</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!--        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />-->
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <script type="text/javascript" src="./js/jquery.min.js"></script>
        <script type="text/javascript" src="./data/sensor.js"></script>
<!--        <script src="./js/vue2.js"></script>-->
        <!-- 开发环境版本，包含了有帮助的命令行警告 -->
        <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    </head>

    <body  >

        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">系统设置</a>
                <a>
                    <cite>系统设置</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">矿名称:</h3>
                            <input type="text" id="input_mine_name" class="layui-input" style="width: 300px; display: inline;"/> &nbsp;&nbsp;<button class = "layui-btn layui-btn-sm" onclick="btn_setMineName()">保存设置</button>
                        </div>
                    </div>
                    <div class="layui-card">
                        <div class="layui-card-body ">
                                  <h3 style="font-weight: bold;"> 背景图</h3>
<!--                            accept="image/svg+xml"-->
                                   <input type="file" id="file_1" accept="image/svg+xml,image/jpeg,image/jpg,image/png" onchange="getPhotoSize(this)"/><button type="" class="layui-btn layui-btn-sm" onclick="upload_FileInfo()">上传</button>
                                  <div><span style="font-size: 6px; color: #FF5722;">注：请选择2000X2000px背景SVG格式文件</span> <a id="a_cad_background"  style="text-decoration:underline;">点击预览</a></div>
                        </div>
                    </div>
                    <div class="layui-card">
                        <div class="layui-card-body ">
                              <h3 style="font-weight: bold;">数据后台首页:</h3>
                                  <input type="text" id="web_home_url" class="layui-input" style="width: 300px; display: inline;"/> &nbsp;&nbsp;<button class = "layui-btn layui-btn-sm" onclick="btn_setWebHomeUrl()">保存设置</button>
                        </div>
                    </div>

                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">一张图首页:</h3>
                            <input type="text" id="map_home_url" class="layui-input" style="width: 300px; display: inline; "/>&nbsp;&nbsp;<button class = "layui-btn layui-btn-sm" onclick="btn_setMapHomeUrl()">保存设置</button>
                        </div>
                    </div>

                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">主题设置:</h3>
                            <select id="select_theme">
                                <option>深色模式</option>
                                <option>高亮模式</option>
                            </select>
                        </div>
                    </div>


                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">数据中断时使用最后一次数据:</h3>
                            启用：<input type="checkbox" id="use_last_data"  onchange="btn_Set_Use_last_data()" />
                        </div>
                    </div>

                    <div class="layui-card" id="app">
                        <div class="layui-card-body ">
                            启用：<input type="checkbox" id="checkbox_phone_msg"  onchange="btn_Set_phone_msg()" />
                        </div>
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">故障报警设置:</h3>
                            <input type="text" id="warning_device_fault" v-model="warning_device_fault"  onBlur="input_warning(this)" placeholder=""/> 分【多少分钟内通知故障】<br>
                            <input type="text" id="warning_device_fault_jiange"  v-model="warning_device_fault_jiange"  onBlur="input_warning(this)"  /> 分【设置间隔多久一次】
                        </div>
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">超标报警设置:</h3>
                            <input type="text" id="warning_overrun_gas"  v-model="warning_overrun_gas"  onBlur="input_warning(this)"  />分 【多少分钟内报警】<br>
                            <input type="text" id="warning_overrun_gas_jiange"   v-model="warning_overrun_gas_jiange"  onBlur="input_warning(this)"  />分【设置间隔多久一次】
                        </div>
                    </div>

                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <h3 style="font-weight: bold;">CO跳数过滤规则:</h3>
                            <span>超过多少时启用跳数过滤异常数:</span><input id="more_than_CO" type="number"  value="8" onblur="saveMoreCO()"/><br>
                            <span>连续上报多少次非零时归为正常:</span><input id="more_than_count" type="number" value="5" onblur="saveMore_than_count()">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/html" id="toolbarMenu">
        <div class = "layui-btn-container" >
<!--            <button class = "layui-btn layui-btn-sm" lay-event = "getCheckData" > 获取选中行数据 </button>-->
<!--            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button >-->
<!--            <button class = "layui-btn layui-btn-sm" lay-event = "addSensor" onclick="xadmin.open('添加设备','./sensor-add.html',600,400)" ><i class="layui-icon"></i> 新增传感器</button>-->
        </div >
    </script>
    <script type="text/html" id="toolbarDemo">


        <div class = "layui-btn-container" >

<!--            <button class = "layui-btn layui-btn-sm" lay-event = "getCheckData" > 获取选中行数据 </button>-->
<!--            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button > -->
<!--            <button class = "layui-btn layui-btn-sm" lay-event = "isAll" > 验证是否全选</button>-->
            <button class = "layui-btn layui-btn-sm"   lay-event = "openDefault" > 开启关闭默认</button>
            <button class="layui-btn layui-btn-sm"  lay-event = "changeDeviceType" > 切换类型</button>
            <button class = "layui-btn layui-btn-danger"   lay-event = "delete" > 删除</button>

        </div >
    </script>


<!--    <script type="text/html" id="switchTpl">-->
<!--        &lt;!&ndash; 这里的checked的状态只是演示 &ndash;&gt;-->
<!--        <input type = "checkbox" name = "sex" value = "{{d.id}}" lay-skin = "switch"lay-text = "女|男" lay-filter = "sexDemo" {{ d.id == 10003 ? 'checked': ''}} >-->
<!--    </script>-->
<!--    <script>layui.use('laydate',-->
<!--        function() {-->
<!--            var laydate = layui.laydate;-->

<!--            //执行一个laydate实例-->
<!--            laydate.render({-->
<!--                elem: '#start' //指定元素-->
<!--            });-->

<!--            //执行一个laydate实例-->
<!--            laydate.render({-->
<!--                elem: '#end' //指定元素-->
<!--            });-->

<!--        });</script>-->

    <script>
        //判断照片大小
        function getPhotoSize(obj){
            photoExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
            // if(photoExt!='.jpg'){
            //     alert("请上传后缀名为jpg的照片!");
            //     return false;
            // }
            var fileSize = 0;
            var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
            if (isIE && !obj.files) {
                var filePath = obj.value;
                var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                var file = fileSystem.GetFile (filePath);
                fileSize = file.Size;
            }else {
                fileSize = obj.files[0].size;
            }
            fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
            if(fileSize>=1024*3){
                alert("底图最大支持3M，请重新上传!");
                $(this).val(null);
                return false;
            }
        }


        //上传文件
        function upload_FileInfo(){
            let formData = new FormData();
            formData.append("file", document.getElementById('file_1').files[0]);
            let url=sensorServer.getUploadFileUrl();
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                success:function(data){
                    console.log(JSON.stringify(data));
                    if(data.msg=="操作成功"&&data.data!=null){
                        let uploadSuccessPath=data.data;
                        let postSData={"appkey":"cad_background","appval":data.data};
                        let resultCount=sensorServer.updateSettingsInfo(postSData);
                        if(resultCount==1) {
                            layer.msg("上传成功！");
                        }else{
                            layer.msg("保存失败！");
                        }
                    }else{
                        alert(JSON.stringify(data));
                        layer.msg("上传失败！");
                    }
                },
                error:function(e){
                    alert("错误！！");

                }
            });
        }

        function btn_setMineName() {
            let inputValue=$("#input_mine_name").val();
            let postSData={"appkey":"mine_name","appval":inputValue,"note":"矿名称"};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

        //设置后台首页URL
        function btn_setWebHomeUrl(){
            let appVal=$("#web_home_url").val();//location.origin+"/index.html";
            //$("#web_home_url").val(appVal);
            let postSData={"appkey":"data_home_url","appval":appVal};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

        //设置一张图首页
        function btn_setMapHomeUrl() {
            let appVal=$("#map_home_url").val();
            let postSData={"appkey":"map_home_url","appval":appVal};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

        // 设置 是否无数据时使用最后一次默认数据
        function  btn_Set_Use_last_data() {
            let appVal=0;
            if($("#use_last_data").is(':checked')){
                appVal=1;
            }
            let postSData={"appkey":"use_last_data","appval":appVal};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }


        // 设置 是否启用短信通知
        function  btn_Set_phone_msg() {
            let appVal=0;
            if($("#checkbox_phone_msg").is(':checked')){
                appVal=1;
            }
            let postSData={"appkey":"phone_send_warning_msg","appval":appVal};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

        // 这里的用的ID 不要随便改 存到了库里了。别的地方用
        function input_warning(va){
            var inputText=$(va).val();
            let inputId=$(va)[0].id;
            let postSData={"appkey":inputId,"appval":inputText};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

        function  saveMoreCO() {
            let inputValue=$("#more_than_CO").val();
            let postSData={"appkey":"more_than_CO","appval":inputValue,"note":"超过多少时启用跳数过滤异常数"};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

        function saveMore_than_count() {
            let inputValue=$("#more_than_count").val();
            let postSData={"appkey":"more_than_count","appval":inputValue,"note":"连续上报多少次非零时归为正常"};
            let resultCount=sensorServer.updateSettingsInfo(postSData);
            if(resultCount==1) {
                layer.msg("保存成功！");
            }else{
                layer.msg("保存失败！");
            }
        }

       // layui.use('table',
       //    function() {
        //       var table = layui.table;
        //
        //         //监听单元格编辑
        //         table.on('edit(test)',
        //             function(obj) {
        //                 var value = obj.value //得到修改后的值
        //                     ,
        //                     data = obj.data //得到所在行所有键值
        //                     ,
        //                     field = obj.field; //得到字段
        //                 layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
        //             });

                //头工具栏事件
           //      table.on('toolbar(test)',
           //          function(obj) {
           //              var checkStatus = table.checkStatus(obj.config.id);
           //              switch (obj.event) {
           //                  case 'getCheckData':
           //                      var data = checkStatus.data;
           //                      layer.alert(JSON.stringify(data));
           //                      break;
           //                  case 'getCheckLength':
           //                      var data = checkStatus.data;
           //                      layer.msg('选中了：' + data.length + ' 个');
           //                      break;
           //                  case 'isAll':
           //                      layer.msg(checkStatus.isAll ? '全选': '未全选');
           //                      break;
           //
           //              };
           //          });
           // });



    </script>

    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data:{
                warning_device_fault:"",
                warning_device_fault_jiange:"",
                warning_overrun_gas:"",
                warning_overrun_gas_jiange:"",
            }
        })
        function initSensorList(dataSensor){
            layui.use('table', function () {
                var table = layui.table;
                //第一个实例
                table.render({
                    elem: '#demo'
                    ,
                    height: 480
                    , data: dataSensor,
                    page: false //开启分页
                    ,limit: 100,
                   // toolbar: '#toolbarMenu',
                    cols: [[ //表头
                         {field: 'pid', title: '编号', width: 80, sort: true, fixed: 'left',hide:true}
                        , {field: 'ch4', title: '甲烷最大警值(%)', width: 200, edit: 'text'}
                        , {field: 'co2', title: '二氧化碳最大警值(%)', width: 200, edit: 'text'}
                        , {field: 'co', title: '一氧化碳最大警值(ppm)', width: 200, edit: 'text'}
                        , {field: 'temperature', title: '温度最大值(℃)', width: 200, edit: 'text'}
                        , {field: 'o2', title: '氧气最低值(%)', width: 200, edit: 'text'}
                        , {field: 'humidity', title: '湿度最大值（RH%）', width: 200, edit: 'text'}
                    ]]
                    ,loading:true,
                    done:function (res, curr, count) {
                        $("[data-field='smokenormal']").children().each(function(){
                            if($(this).text()!=''){
                                $(this).text("正常")
                            }
                                // else if($(this).text()=='0'){
                            //     $(this).text("正常")
                            // }
                           // $(this).text("正常")
                        });
                    }
                });

                //监听单元格编辑
                table.on('edit(test_table)',
                    function (obj) {
                        var value = obj.value //得到修改后的值
                            ,
                            data = obj.data //得到所在行所有键值
                            ,
                            field = obj.field; //得到字段
                        //layer.msg('[ID: ' + data.pid + '] ' + field + ' 字段更改为：' + value);
                        layer.msg(field + ' 字段更改为：' + value);
                        var jsonResult = sensorServer.updateMaxSetting(obj.data);
                        console.log(jsonResult);
                    });

                //监听行单击事件（双击事件为：rowDouble）
                //table.on('row(test_table)', function(obj){
                // var data = obj.data;
                // layer.alert(JSON.stringify(data), {
                //     title: '当前行数据：'
                // });

                //标注选中样式
                //obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                //  });

                //头工具栏事件
                table.on('toolbar(toolbarDemo)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.pid);
                    switch (obj.event) {
                        case 'delete':
                            layer.msg('data:'+obj.data.pid);
                            //del(obj);
                            break;
                    };
                });
                //列里的工具栏
                table.on('tool(test_table)',
                    function(obj) {
                        //var checkStatus = table.checkStatus(obj.config.pid);
                        // switch (obj.event) {
                        //     case 'delete':
                        //         layer.msg('data:'+obj.data.pid);
                        //         del(obj);
                        //         break;
                        //     case 'openDefault':
                        //         layer.msg('data:'+obj.data.pid);
                        //         openDefaultClick(obj);
                        //         break;
                        //     case 'changeDeviceType':
                        //             layer.msg('data:'+obj.data.pid);
                        //             changeDeviceType(obj);
                        //             break;
                        // };
                    });
            });
        }

        function getData(){
             dataSensor=sensorServer.getMaxSetting({"page":1,"rows":1000});
             return dataSensor;
        }
        //加载默认数据
        $(function () {
            initPageSetInfo();
            var  dataSensor=getData();
            if (dataSensor!=null&&dataSensor!=undefined){
                initSensorList(dataSensor.data);
            }else{
                layer.msg('加载失败！!',{icon:1,time:1000});
            }
        })

        function sensorInfo(pid,deviceId){
            this.pid=pid;
            this.deviceId=deviceId;
        }
        function  del(obj){
            layer.confirm('确认要删除吗？',function(index){
                //发异步删除数据
                //sensorServer.delSensorInfo11(obj.data);
               //  $(obj).parents("tr").remove();
               //  $(obj).remove();
               // layer.msg('已删除!',{icon:1,time:1000});
               // location.reload();
            });
        }
        function  openDefaultClick(obj){

        }

        function  changeDeviceType(obj) {

        }

        function  updateMaxSetting(obj) {

        }

        function  initPageSetInfo() {
            initMineName();
            initDataHomeIndexUrl();
            initCadBackground();
            init_map_home_url();
            init_use_last_data();
            init_phone_send_warning_msg();
            f_device_baojing();
            f_morthanCO();
        }

        //获取矿名称
        function  initMineName() {
            let postData={"appkey":"mine_name"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null){
                    $("#input_mine_name").val(settingsInfo.appval);
                }
            }
        }
        //获取设置的首页
        function  initDataHomeIndexUrl() {
            let postData={"appkey":"data_home_url"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null){
                    $("#web_home_url").val(settingsInfo.appval);
                }
            }

        }

        //获取设置的首页
        function  initCadBackground() {
            let postData={"appkey":"cad_background"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null){
                    $("#a_cad_background").attr('href',settingsInfo.appval);
                }
            }
        }

        //设置一张图首页
        function  init_map_home_url() {
            let postData={"appkey":"map_home_url"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null){
                    $("#map_home_url").val(settingsInfo.appval);
                }
            }
        }

        //获取是否开启了默认数据
        function init_use_last_data() {
            let postData={"appkey":"use_last_data"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null) {
                    if (settingsInfo.appval == "1") {
                        $("#use_last_data").attr("checked", "checked");
                    }
                }
            }
        }

        function  init_phone_send_warning_msg() {
            let postData={"appkey":"phone_send_warning_msg"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null) {
                    if (settingsInfo.appval == "1") {
                        $("#checkbox_phone_msg").attr("checked", "checked");
                    }
                }
            }
        }

        //设置报警规则显示
        function f_device_baojing() {
            let postData={"appkey":"warning_device_fault"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null) {
                    app.warning_device_fault=settingsInfo.appval;
                }
            }
            if(2==2){
                let postData={"appkey":"warning_device_fault_jiange"};
                let settingsInfo=sensorServer.getSettingsByAppKey(postData);
                if(settingsInfo!=undefined&&settingsInfo!=null){
                    if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null) {
                        app.warning_device_fault_jiange=settingsInfo.appval;
                    }
                }
            }
            if(3==3){
                let postData={"appkey":"warning_overrun_gas"};
                let settingsInfo=sensorServer.getSettingsByAppKey(postData);
                if(settingsInfo!=undefined&&settingsInfo!=null){
                    if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null) {
                        app.warning_overrun_gas=settingsInfo.appval;
                    }
                }
            }
            if(4==4){
                let postData={"appkey":"warning_overrun_gas_jiange"};
                let settingsInfo=sensorServer.getSettingsByAppKey(postData);
                if(settingsInfo!=undefined&&settingsInfo!=null){
                    if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null) {
                        app.warning_overrun_gas_jiange=settingsInfo.appval;
                    }
                }
            }
        }

        //一氧化碳过滤数据规则
        function f_morthanCO() {
            let postData={"appkey":"more_than_CO"};
            let settingsInfo=sensorServer.getSettingsByAppKey(postData);
            if(settingsInfo!=undefined&&settingsInfo!=null){
                if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null){
                    $("#more_than_CO").val(settingsInfo.appval);
                }
            }
            if(2==2){
                let postData={"appkey":"more_than_count"};
                let settingsInfo=sensorServer.getSettingsByAppKey(postData);
                if(settingsInfo!=undefined&&settingsInfo!=null){
                    if(settingsInfo.appval!=undefined&&settingsInfo.appval!=null){
                        $("#more_than_count").val(settingsInfo.appval);
                    }
                }
            }
        }

    </script>



</html>
